import express from "express";
import { formatResponse } from "../../utils/tools";
import { CaptchaService } from "../../services/system/CaptchaService";
const router = express.Router();

// 获取验证吗
router.get("/", async (req: any, res) => {
  const captcha = await CaptchaService.getCaptchaImg();

  req.session.captcha = captcha.text;

  let data = formatResponse<typeof captcha.data>(captcha.data) as any;
  data.captchaEnabled = +captcha.enableCaptcha === 1;

  if (!data.captchaEnabled) {
    data.data = null;
  }
  res.send(data);
});

export default router;
